lib/commit: Ensure bare-user objects are always user-readable
authorColin Walters <walters@verbum.org>
Fri, 30 Jun 2017 13:40:47 +0000 (09:40 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 30 Jun 2017 21:23:48 +0000 (21:23 +0000)
Some of the Jenkins jobs for Fedora Atomic Host broke after updating
to 2017.7, and it turns out that we regressed handling unreadable
files in `bare-user` mode.  An example of this is `/etc/shadow`, which
ends up in the ostree-as-host content as `/usr/etc/shadow`.

Now there are better fixes here; we should probably delete it and create it
during the config merge if it doesn't exist.  In general, having secret files in
ostree really isn't supported, so it doesn't make sense to include them.

But let's fix this regression - when operating as an unprivileged user we don't
have `CAP_DAC_OVERRIDE` and hence will fail to open un-user-readable objects.

(We still preserve the actual `0` mode of course in the xattr and will
 apply it in `bare`)

Closes: #989
Approved by: jlebon

src/libostree/ostree-repo-commit.c
tests/test-basic-user.sh

index bc55fd6f971756b79af6e8c5da75f22a6e1d7190..1ecbc178620ac57250fef019e4546b9d0d1996a1 100644 (file)
@@ -253,13 +253,15 @@ commit_loose_regfile_object (OstreeRepo        *self,
       /* Note that previously this path added `| 0755` which made every
        * file executable, see
        * https://github.com/ostreedev/ostree/issues/907
+       * We then changed it to mask by 0775, but we always need at least read
+       * permission when running as non-root, so explicitly mask that in.
        *
        * Again here, symlinks in bare-user are a hairy special case; only do a
        * chmod for a *real* regular file, otherwise we'll take the default 0644.
        */
       if (S_ISREG (mode))
         {
-          const mode_t content_mode = (mode & (S_IFREG | 0775));
+          const mode_t content_mode = (mode & (S_IFREG | 0775)) | S_IRUSR;
           if (fchmod (tmpf->fd, content_mode) < 0)
             return glnx_throw_errno_prefix (error, "fchmod");
         }
index fa802df67ea97bdbdb865da51640bb698c339f47..94866550dafe34cb62e155272c6f090a980ef48d 100755 (executable)
@@ -25,7 +25,7 @@ skip_without_user_xattrs
 
 setup_test_repository "bare-user"
 
-extra_basic_tests=3
+extra_basic_tests=4
 . $(dirname $0)/basic-test.sh
 
 # Reset things so we don't inherit a lot of state from earlier tests
@@ -64,3 +64,16 @@ $OSTREE checkout -U -H test2-unwritable test2-checkout
 cd test2-checkout
 assert_file_has_mode unwritable 400
 echo "ok bare-user unwritable"
+
+rm test2-checkout -rf
+$OSTREE checkout -U -H test2 test2-checkout
+cat > statoverride.txt <<EOF
+=0 /unreadable
+EOF
+touch test2-checkout/unreadable
+$OSTREE commit -b test2-unreadable --statoverride=statoverride.txt --tree=dir=test2-checkout
+$OSTREE fsck
+rm test2-checkout -rf
+$OSTREE checkout -U -H test2-unreadable test2-checkout
+assert_file_has_mode test2-checkout/unreadable 400
+echo "ok bare-user handled unreadable file"